package cn.lyh.gulimall.member.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.lyh.gulimall.member.entity.UmsMember;
import cn.lyh.gulimall.member.dao.UmsMemberMapper;
import utils.PageUtils;

/**
 * @author lyh
 * @version 1.0
 * @since 2021/4/6
 */
@Service
public class UmsMemberService extends ServiceImpl<UmsMemberMapper, UmsMember> {
	@Autowired
	UmsMemberMapper memberMapper;

	public PageUtils getMemberListByPage(Map<String, Object> params) {

		// 获取key
		String key= (String) params.get("key");

		QueryWrapper<UmsMember> umsMemberQueryWrapper = new QueryWrapper<>();
		if (StringUtils.isNotEmpty(key)){
			umsMemberQueryWrapper.eq(UmsMember.COL_MOBILE,key).or().like(UmsMember.COL_NICKNAME,key);
		}

		//获取分页参数
		// 获取分页数据
		long curPage = params.get("page") != null ? Long.parseLong((String) params.get("page")) : 1;
		long limit = params.get("limit") != null ? Long.parseLong((String) params.get("limit")) : 10;

		//创建分页模型
		Page<UmsMember> page = new Page<UmsMember>(curPage,limit);
		// 调用mapper
		Page<UmsMember> umsMemberPage = memberMapper.selectPage(page, umsMemberQueryWrapper);
		PageUtils pageUtils = new PageUtils(umsMemberPage);
		return pageUtils;

	}
}
